﻿Namespace Forms.List
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
    Public Class frmCertificationEarnedLessonsList
        Inherits frmBaseGrid

#Region "Designer"

        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

        Friend WithEvents ucCertificationEarnedLessonsList As ucCertificationEarnedLessonsList

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.ucCertificationEarnedLessonsList = New IIC.ucCertificationEarnedLessonsList()
            Me.pnlGrid.SuspendLayout()
            Me.SuspendLayout()
            '
            'pnlGrid
            '
            Me.pnlGrid.Controls.Add(Me.ucCertificationEarnedLessonsList)
            Me.pnlGrid.Location = New System.Drawing.Point(0, 53)
            Me.pnlGrid.Size = New System.Drawing.Size(887, 389)
            '
            'ucCertificationRequirementList
            '
            Me.ucCertificationEarnedLessonsList.Dock = System.Windows.Forms.DockStyle.Fill
            Me.ucCertificationEarnedLessonsList.Location = New System.Drawing.Point(0, 0)
            Me.ucCertificationEarnedLessonsList.Name = "ucCertificationRequirementList"
            Me.ucCertificationEarnedLessonsList.Size = New System.Drawing.Size(887, 389)
            Me.ucCertificationEarnedLessonsList.TabIndex = 0
            '
            'frmCertificationRequirementList
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(7.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(887, 442)
            Me.Name = "frmCertificationRequirementList"
            Me.ShowConfigButton = True
            Me.ShowExcelButton = True
            Me.ShowPrintButton = True
            Me.ShowSearch = True
            Me.Text = "frmCertificationRequirementList"
            Me.Controls.SetChildIndex(Me.pnlGrid, 0)
            Me.pnlGrid.ResumeLayout(False)
            Me.ResumeLayout(False)

        End Sub

#End Region

#Region "Standard Code"

        Private Sub frmCertificationRequirementList_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
           Handles Me.Load

            Me.setReadOnly(True)
            Me.ShowExcelButton = False
            Me.addToolbarActionButton("Previous", AddressOf goPrevious, 100, Global.org.codegen.win.controls.My.Resources.Resources.GoRtlHS)
            Me.addToolbarActionButton("Next", AddressOf goNext, 100, Global.org.codegen.win.controls.My.Resources.Resources.GoLtrHS)

        End Sub

        ''' <summary>
        ''' This function is common to all forms that inherit from class frmBaseGrid
        ''' It priovides a common name to the underlying grid control that shows the records
        ''' </summary>
        Public Overrides Function grdData() As org.codegen.win.controls.Grid.CGBaseGrid
            Return Me.ucCertificationEarnedLessonsList.grdCertificationRequirement
        End Function

        Protected Sub DeleteRecordConfirmed() Handles Me.gridDeleteRecordConfirmed

            Dim m As New CertificationRequirementDBMapper
            Dim mo As CertificationRequirement = m.findByKey(Me.grdData.IdValue)
            Call m.delete(mo)

        End Sub

#End Region

        Private grdMover As GridMoveNextPrevious

        Sub loadCertificateEarnedHistory(ByVal parentGrid As Grid.CGBaseGrid)

            Me.grdMover = New GridMoveNextPrevious(Me, parentGrid)
            Me.grdMover.MoveCurrent()

        End Sub

        Private Sub goPrevious(ByVal sender As Object, ByVal e As System.EventArgs)
            Me.grdMover.MovePrevious()
        End Sub

        Private Sub goNext(ByVal sender As Object, ByVal e As System.EventArgs)
            Me.grdMover.MoveNext()
        End Sub

    End Class

    Public Class GridMoveNextPrevious
        Implements IMoveNextPrevious

        Private parentGrid As Grid.CGBaseGrid
        Private parentForm As frmCertificationEarnedLessonsList

        Sub New(ByVal _parentForm As frmCertificationEarnedLessonsList, ByVal _parentGrid As Grid.CGBaseGrid)
            Me.parentGrid = _parentGrid
            Me.parentForm = _parentForm
        End Sub

        Private Function getCurrentCertificationEarnedId() As Integer

            Return CInt(Me.parentGrid.SelectedRows(0).Cells("CertificationEarnedId").Value)

        End Function

        Public Sub MoveCurrent() Implements IMoveNextPrevious.MoveCurrent

            If Me.parentGrid.SelectedRows.Count = 0 Then
                Me.parentGrid.Rows(0).Selected = True 'goto first
            End If
            Me.parentForm.ucCertificationEarnedLessonsList.grdCertificationRequirement.gpWhereclause = " CertificationEarnedId=" & getCurrentCertificationEarnedId()
            Me.parentForm.ucCertificationEarnedLessonsList.grdCertificationRequirement.loadGrid()

        End Sub
        Public Sub MoveNext() Implements IMoveNextPrevious.MoveNext

            If Me.parentGrid.SelectedRows.Count > 0 Then

                Dim selRowIdx As Integer = Me.parentGrid.SelectedRows(0).Index
                Dim newRowIdx As Integer = selRowIdx + 1

                If newRowIdx > (Me.parentGrid.Rows.Count - 1) Then
                    newRowIdx = 0
                End If


                Me.parentGrid.Rows(selRowIdx).Selected = False
                Me.parentGrid.Rows(newRowIdx).Selected = True

                Call MoveCurrent()

            End If
        End Sub

        Public Sub MovePrevious() Implements IMoveNextPrevious.MovePrevious

            If Me.parentGrid.SelectedRows.Count > 0 Then

                Dim selRowIdx As Integer = Me.parentGrid.SelectedRows(0).Index
                Dim newRowIdx As Integer = selRowIdx - 1
                If (selRowIdx = 0) Then
                    newRowIdx = Me.parentGrid.RowCount - 1
                End If

                Me.parentGrid.Rows(selRowIdx).Selected = False
                Me.parentGrid.Rows(newRowIdx).Selected = True
                Call MoveCurrent()

            End If

        End Sub
    End Class

End Namespace 

